Learn R Programming

gmat (version 0.2.1)

dag-constrained correlation matrices: Simulation of correlation matrices

Description

Sample correlation matrices, possibly with a zero pattern in its Cholesky decomposition constrained by an acyclic digraph.

Usage

chol_mh(N = 1, p = 3, d = 1, dag = NULL, ...)

chol_iid(N = 1, p = 3, d = 1, dag = NULL)

Arguments

N

Number of samples.

p

Matrix dimension. Ignored if dag is provided.

d

Number in [0,1], the proportion of non-zero entries in the Cholesky factor of the sampled matrices. Ignored if dag is provided.

dag

An igraph acyclic digraph specifying the zero pattern in the upper Cholesky factor of the sampled matrices. Nodes must be in ancestral order, with the first one having no parents.

...

Additional parameters for mh_u().

Value

A three-dimensional array of length p x p x N.

Details

Function chol_mh() uses the method described in C<U+00F3>rdoba et al. (2018) and implemented in mh_u(), based on a Metropolis-Hastings algorithm over the upper Cholesky factorization.

The entries in the upper Cholesky factor are sampled i.i.d. by function chol_iid(), following Kalisch and Buhlmann (2007).

References

C<U+00F3>rdoba I., Varando G., Bielza C., Larra<U+00F1>aga P. A fast Metropolis-Hastings method for generating random correlation matrices. Lecture Notes in Computer Science (IDEAL 2018), vol 11314, pp. 117-124, 2018.

Kalisch, M., Buhlmann, P. Estimating high-dimensional directed acyclic graphs with the PC-algorithm, Journal of Machine Learning Research, 8:613-636, 2007.

Examples

Run this code
# NOT RUN {
## Cholesky sampling via Metropolis-Hastings
# Generate a full matrix (default behaviour)
chol_mh()

# Generate a matrix with a percentage of zeros
chol_mh(d = 0.5)

# Generate a random acyclic digraph structure
dag <- rgraph(p = 3, d = 0.5, dag = TRUE)
igraph::print.igraph(dag)

# Generate a matrix complying with the predefined zero pattern
chol_mh(dag = dag)
## Cholesky sampling via i.i.d. Cholesky factor
# Generate a full matrix (default behaviour)
chol_iid()

# Generate a matrix with a percentage of zeros
chol_iid(d = 0.5)

# Generate a matrix complying with the predefined zero pattern
igraph::print.igraph(dag)
chol_iid(dag = dag)
# }

Run the code above in your browser using DataLab